<?php

namespace app\widgets;


use app\models\Categories;
use yii\base\Widget;
use yii\helpers\Html;
use yii\helpers\Url;

class CategoryWidget extends Widget {

    public $type = Categories::TYPE_VIDEO;

    public function run() {
        $models = Categories::find()->where(['type' => $this->type])->andWhere(['>', 'parent_id', 0])->asArray()->all();
        $data = [];
        foreach ($models as $model) {
            $url = Url::to(['category/', 'slug' => strtolower($model['slug'])]);
            $link = Html::a($model['title'], $url);
            $data[] = Html::tag('div', $link, ['class' => 'column col-4 col-md-3 col-lg-6 text-center']);
        }
        return join("\n", $data);
    }
}